package com.manager.devicemanager.controller;

import com.manager.devicemanager.common.DataSourceNameEnum;
import com.manager.devicemanager.common.Result;
import com.manager.devicemanager.service.IAlarmrecordsService;
import com.manager.devicemanager.vo.AlarmrecordsVO;
import com.manager.devicemanager.vo.ComponentStatusRequestVO;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author wpf
 * @since 2025-06-24
 */
@RestController
@RequestMapping("/alarmrecords")
public class AlarmrecordsController {
    @Autowired
    private IAlarmrecordsService iAlarmrecordsService;

    @Operation(summary = "条件查询带分页")
    @PostMapping("/list")
    public Result<List<AlarmrecordsVO>> list(@RequestBody ComponentStatusRequestVO componentStatusRequestVO ){
        List<AlarmrecordsVO>  alarmrecordsIPage =iAlarmrecordsService.getPage("ic".equals(componentStatusRequestVO.getType())?DataSourceNameEnum.ICBOARDCONFIG.getDataSourceName()+componentStatusRequestVO.getDatasourceindex():DataSourceNameEnum.PDBOARDCONFIG.getDataSourceName()+componentStatusRequestVO.getDatasourceindex());
//        List<AlarmrecordsVO> alarmrecordsIPage1 =iAlarmrecordsService.getICPage(DataSourceNameEnum.ICBOARDCONFIG.getDataSourceName()+"1");
//        if (alarmrecordsIPage1!= null) {
//          alarmrecordsIPage.addAll(alarmrecordsIPage1);
//        }
        alarmrecordsIPage.sort((a, b) -> b.getTime().compareTo(a.getTime()));
        return Result.success(alarmrecordsIPage);
    }


}
